package com.andy.common.db.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.andy.common.db.entity.UserEntity

/**
 * Author:Andy
 * Date:2023/3/21 15:41
 * Description:UserDao
 */
@Dao
interface UserDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUser(user: UserEntity): Long

    @Delete
    fun deleteUser(user: UserEntity)

    @Query("DELETE FROM user_table WHERE id =:id")
    fun deleteUser(id: Long)

    @Query("DELETE FROM user_table")
    fun deleteAll()

    @Update
    fun updateUser(user: UserEntity)

    @Query("UPDATE user_table SET name=:name WHERE id=:id")
    fun updateUser(id: Long, name: String)

    @Query("SELECT * FROM user_table WHERE id =:id")
    fun getUser(id: Long): LiveData<UserEntity>

    @Query("SELECT * FROM user_table")
    fun getAllUsers(): List<UserEntity>

}